Print the index of the characterΒΆ
Print the index of the character in a string.
Sample string: w3resource
Expected output:
Current character w position at 0
Current character 3 position at 1
Current character r position at 2
- - - - - - - - - - - - - - - - - - - - - - - - -
Current character c position at 8
Current character e position at 9
S = "w3resource"
for index, char in enumerate(S):
print("Current character", char, "position at", index )
Output:
Current character w position at 0
Current character 3 position at 1
Current character r position at 2
Current character e position at 3
Current character s position at 4
Current character o position at 5
Current character u position at 6
Current character r position at 7
Current character c position at 8
Current character e position at 9